Ext.define('TS.lib.Store', {
	extend: 'Ext.data.Store',
	autoLoad: false,
	
	constructor:function(){// bot o nie komponent
		this.callParent(arguments);// musi byc, i to musi byc przed this.on !
		//this.initConfig(arguments[0]);// to jak widac niemusi 
		this.on('load',this.onLoad);// zamiast onException
	},
	
	onLoad:function(store,records,success,operation){
		
		var d = store.getProxy().reader.jsonData;
		
		if(!success || d.success === false){
			
			if(!d.session && (!d.reason || d.reason != CONST.reason.auth)){
				Util.error.display(d);
			} else {
				Util.error.display(d);
				if (d && d.company)USER.company = d.company;
				APP.session.fail();
			}
		}
	},
	remoteSort:true,		
	listeners:{
		remove:function(){
			this.setBaseParam('where',null);
		}
	},
	setBaseParam: function (name, value){
		this.proxy.extraParams = this.proxy.extraParams || {};
		this.proxy.extraParams[name] = value;
		this.proxy.applyEncoding(this.proxy.extraParams);
		return this;// for chaining
	},
	getGroupString: function(instance) {
        var group = this.groupers.first();
        if (group) {
        	if(group.groupStringFn){
        		return group.groupStringFn(instance);
        	} else {
        		return instance.get(group.property);
        	}
        }
        return '';
    }
});
